package solutions.leetcode.easy;

import solutions.lib.BaseSolution;

/**
 * @author lizhidong
 * <a href="https://leetcode-cn.com/problems/reformat-date/">1507. 转变日期格式</a>
 */
public class Solution1507 extends BaseSolution {

    public String reformatDate(String date) {
        String[] parts = date.split(" ");

        int day = 0, p = 0;
        while (p < parts[0].length()) {
            char c = parts[0].charAt(p++);
            if (c >= '0' && c <= '9') {
                day = day * 10 + (c - '0');
            } else {
                break;
            }
        }
        String dayStr = day < 10 ? "0" + day : String.valueOf(day);
        String monStr = "";
        switch (parts[2]) {
            case "Jan": monStr = "01"; break;
            case "Feb": monStr = "02"; break;
            case "Mar": monStr = "03"; break;
            case "Apr": monStr = "04"; break;
            case "May": monStr = "05"; break;
            case "Jun": monStr = "06"; break;
            case "Jul": monStr = "07"; break;
            case "Aug": monStr = "08"; break;
            case "Sep": monStr = "09"; break;
            case "Oct": monStr = "10"; break;
            case "Nov": monStr = "11"; break;
            case "Dec": monStr = "12"; break;
        }
        return parts[2] + "-" + monStr + "-" + dayStr;
    }

    public static void main(String[] args) {
        Solution1507 solution = new Solution1507();
    }
}